<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('大区会长产品合作列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <label>大区会长：</label>
                                <input id="agentName" type="text" name="agentName"/>
                            </li>
                            <li>
                                <label>会长名称：</label>
                                <input id="agentPerson" type="text" name="agentPerson"/>
                            </li>
                            <li>
                                <label>会长电话：</label>
                                <input id="agentPhone" type="text" name="agentPhone"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input id="partsName" type="text" name="partsName"/>
                            </li>
                            <!--<li>
                                <label style="width: 140px;">区域内人口总数：</label>
                                <input type="text" name="peopleNum"/>
                            </li>-->
                            <!--<li>
                                <label>销售额：</label>
                                <input type="text" name="salesVolume"/>
                            </li>
                            <li>
                                <label>保证金：</label>
                                <input type="text" name="earnestMoney"/>
                            </li>-->
                            <li>
                                <label style="width: 140px;">是否缴纳保证金：</label>
                                <select id="isPay" name="isPay" th:with="type=${@dict.getType('zsyh_yesno')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <!--<li>
                                <label style="width: 140px;">人口销售额比例：</label>
                                <input type="text" name="populationSalesRatio"/>
                            </li>
                            <li>
                                <label style="width: 140px;">销售额定金比例：</label>
                                <input type="text" name="salesPaymentRatio"/>
                            </li>-->
                            <li>
                                <label style="width: 140px;">合作产品的年份：</label>
                                <input id="year" type="text" name="year"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="zsyh:agentCooperate:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zsyh:agentCooperate:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zsyh:agentCooperate:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zsyh:agentCooperate:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
                <div style="padding:0px 2px;float: left;margin-left: 20px;align-items: center;height: 40px;line-height:40px;border: #ffebc8 solid 2px">
                    <p><span style="color: red;font-weight: bolder;font-size: medium">合计保证金：</span><span style="font-size: medium;color: red;font-weight: bolder" id="sumEarnestMoney"></span></p></p>
                </div>
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:agentCooperate:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:agentCooperate:remove')}]];
        var isPayDatas = [[${@dict.getType('zsyh_yesno')}]];
        var prefix = ctx + "zsyh/agentCooperate";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "大区会长产品合作",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                onLoadSuccess: function (data) {
                $.ajax({
                    url: ctx + "zsyh/agentCooperate/getSumEarnestMoney?agentName="+$("#agentName").val()+"&agentPerson="+$("#agentPerson").val()+"&agentPhone="+$("#agentPhone").val()+"&partsName="+$("#partsName").val()+"&year="+$("#year").val()+"&isPay="+$('#isPay  option:selected').val()+"&beginCreateTime="+$("#startTime").val()+"&endCreateTime="+$("#endTime").val(),
                    type: "post",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                        debugger
                        $("#sumEarnestMoney").html(result.msg);
                    }
                })
            },
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '大区会长产品合作id',
                    visible: false
                },
                {
                    field: 'agentName',
                    align: 'center',
                    title: '大区会长'
                },{
                    field: 'agentPerson',
                    align: 'center',
                    title: '会长名称'
                },{
                    field: 'agentPhone',
                    align: 'center',
                    title: '联系方式'
                },
                    {
                        field: 'year',
                        align: 'center',
                        title: '合作产品的年份'
                    },
                {
                    field: 'partsName',
                    align: 'center',
                    title: '产品名称'
                },
                {
                    field: 'salesVolume',
                    align: 'center',
                    title: '销售额'
                },
                {
                    field: 'earnestMoney',
                    align: 'center',
                    title: '保证金'
                },
                    {
                        field: 'peopleNum',
                        align: 'center',
                        title: '区域内人口总数'
                    },
                /*{
                    field: 'cooperationPolicy',
                    align: 'center',
                    title: '政策简介'
                },*/
                {
                    field: 'isPay',
                    align: 'center',
                    title: '是否已缴纳保证金',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isPayDatas, value);
                    }
                },
                {
                    field: 'populationSalesRatio',
                    align: 'center',
                    title: '人口销售额比例'
                },
                {
                    field: 'salesPaymentRatio',
                    align: 'center',
                    title: '销售额定金比例'
                },{
                    field: 'reallySalesVolume',
                    align: 'center',
                    title: '实际应完成销售额'
                },{
                    field: 'reallyEarnestMoney',
                    align: 'center',
                    title: '实缴保证金'
                },{
                    field: 'operateName',
                    align: 'center',
                    title: '操作人'
                },

                /*{
                    field: 'remarks',
                    align: 'center',
                    title: '备注'
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewOrder(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        if(row.isPay == "0"){
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="ensurePayment(\'' + row.id + '\')"><i class="fa fa-check"></i>确认收款</a>');
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function viewOrder(id) {
            var url = prefix + "/edit/"+id;
            layer.open({
                type: 2,
                area: [($(window).width()-50) + 'px', ($(window).height()-50) + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "查看详情",
                content:  url,
                closeBtn: 1,
                // 弹层外区域关闭
                shadeClose: true,
                end: function(){
                    //location.reload();
                },
                cancel: function(index) {
                    //location.reload();
                }
            });
        }

        function ensurePayment(id) {
            /*$.modal.confirm("确定收到保证金了吗？", function() {
                debugger;
                var url =prefix + "/edit";
                var data = { "id": id ,"isPay":"1"};
                $.operate.submit(url, "post", "json", data,function () {
                    $("#bootstrap-table").bootstrapTable('refresh');
                });
            });*/
            var url = prefix + "/reviewAgentCooperate/"+id;
            layer.open({
                type: 2,
                area: ['500px', '500px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "确认收款",
                content: url,
                closeBtn: 1,
                /*btn: ['通过', '驳回'],*/
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    $.modal.alertWarning("确认收款");
                    var $tableFlows = $('#bootstrap-table');
                    var pg = $tableFlows.bootstrapTable('getOptions').pageNumber;  //获取当前页码
                    // 跳转到对应的页面
                    $tableFlows.bootstrapTable('selectPage', parseInt(pg));
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

    </script>
</body>
</html>